package com.itsu.mysql.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.itsu.interfaces.entity.UserResult;
import com.itsu.interfaces.service.ScoreService;
import com.itsu.interfaces.service.UserResultService;
import com.itsu.mysql.mappers.ScoreMapper;
import com.itsu.mysql.mappers.UserResultMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class UserResultServiceImpl implements UserResultService {

    @Autowired
    UserResultMapper userResultMapper;


    @Override
    public void save(UserResult userResult) {
        userResultMapper.insert(userResult);
    }

    @Override
    public void updateByUid(UserResult userResult) {
        userResultMapper.update(userResult, Wrappers.lambdaUpdate(UserResult.class).eq(UserResult::getUserId, userResult.getUserId()));
    }

    @Override
    public UserResult findByUid(Long uid) {
        return userResultMapper.selectOne(Wrappers.lambdaQuery(UserResult.class).eq(UserResult::getUserId, uid));
    }

    @Override
    public List<UserResult> findListByRid(Long rid, Long uid) {
        return userResultMapper.selectList(Wrappers.lambdaQuery(UserResult.class)
                .eq(UserResult::getResultId, rid)
                .ne(UserResult::getUserId, uid)
                .orderByDesc(UserResult::getId)
                .last("limit 5"));
    }
}
